//
//  MailView.m
//  LStyle
//
//  Created by Obaid Abdul Maroof on 12/16/09.
//  Copyright 2009 Vrije University. All rights reserved.
//

#import "MailView.h"


@implementation MailView

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];
	
	[tvInbox setSeparatorStyle:UITableViewCellSeparatorStyleNone];
	[tvInbox setHidden:TRUE];
	[activityIndicator startAnimating];
	
	self.createFooter;
	tcMail = [[UITabBar alloc] initWithFrame:CGRectMake(0, 480-50, 320, 30)];
	
	[tcMail addSubview:lblInbox];
	[tcMail addSubview:lblSent];
	[tcMail addSubview:lblCompose];
	
	[self.view addSubview:tcMail];
	
	currentView = inboxView;
	lblCurrent = lblInbox;
	
}

- (void)viewDidAppear:(BOOL)animated{
	
	tvInbox.delegate = self;
	tvInbox.dataSource = self;
	
	[tvInbox reloadData];
	[activityIndicator stopAnimating];
	activityIndicator.hidden = TRUE;
	tvInbox.hidden = FALSE;
}


-(void) createFooter{
	UIFont *fnt = [UIFont fontWithName:@"Verdana" size: 10.0];
	lblInbox = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 60, 20)];
	lblSent = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 70, 20)];
	lblCompose = [[UILabel alloc] initWithFrame:CGRectMake(165, 5, 70, 20)];
	
	
	lblInbox.textAlignment = UITextAlignmentCenter;
	lblSent.textAlignment = UITextAlignmentCenter;
	lblCompose.textAlignment = UITextAlignmentCenter;
	
	[lblInbox setBackgroundColor:[UIColor darkGrayColor]];
	[lblSent setBackgroundColor:[UIColor clearColor]];
	[lblCompose setBackgroundColor:[UIColor clearColor]];
	
	lblInbox.text = @"Inbox";
	lblSent.text = @"Sent";
	lblCompose.text = @"Compose";
	
	lblInbox.font = fnt;
	lblSent.font = fnt;
	lblCompose.font = fnt;
	
	lblInbox.textColor = [UIColor whiteColor];	
	lblSent.textColor = [UIColor whiteColor];	
	lblCompose.textColor = [UIColor whiteColor];		
	
	lblInbox.userInteractionEnabled = YES;
	lblSent.userInteractionEnabled = YES;
	lblCompose.userInteractionEnabled = YES;
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


#pragma mark UITableView Delegate mehods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 80;
}

/*- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
 Album *a = [[Album alloc] initWithNibName:@"Album" bundle:[NSBundle mainBundle]];
 [self.navigationController pushViewController:a animated:YES];
 [a release];
 }*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	int row = indexPath.row;
	UITableViewCell *cell = [tvInbox dequeueReusableCellWithIdentifier:@"cell"];
	if (cell == nil)
	{
		cell = [[[InboxCellView alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];		
	}		
	return cell;
}


/*
 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
 NSSet *allTouches = [event allTouches];
 
 UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
 
 if (touch.view == lblLatest && lblCurrent != lblLatest){
 vcThreadView = [[ThreadView alloc] initWithNibName:@"ThreadView" bundle:[NSBundle mainBundle]];
 [lblCurrent setBackgroundColor:[UIColor clearColor]];
 lblCurrent = strNum;
 [lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
 currentView = vcThreadView.view;
 
 CGRect rect = subView.frame;
 subView.hidden = TRUE;
 vcThreadView.view.frame = rect;
 
 [self.view addSubview:vcThreadView.view];
 }
 
 if (touch.view == lblBack && lblCurrent != lblBack){
 vcThreadView = [[ThreadView alloc] initWithNibName:@"ThreadView" bundle:[NSBundle mainBundle]];
 [lblCurrent setBackgroundColor:[UIColor clearColor]];
 lblCurrent = lblBack;
 [lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
 
 CGRect rect = subView.frame;
 subView.hidden = TRUE;
 vcThreadView.view.frame = rect;
 
 [self.view addSubview:vcThreadView.view];
 }
 
 if (touch.view == lblForward && lblCurrent != lblForward){
 vcThreadView = [[ThreadView alloc] initWithNibName:@"ThreadView" bundle:[NSBundle mainBundle]];
 [lblCurrent setBackgroundColor:[UIColor clearColor]];
 lblCurrent = lblForward;
 [lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
 
 CGRect rect = subView.frame;
 subView.hidden = TRUE;
 vcThreadView.view.frame = rect;
 
 [self.view addSubview:vcThreadView.view];
 }
 
 if (touch.view == strComent && lblCurrent != strComent){
 
 currentView.hidden = TRUE;
 [lblCurrent setBackgroundColor:[UIColor clearColor]];
 lblCurrent = strComent;
 [lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
 
 subView.hidden = FALSE;
 currentView = subView;
 
 
 }
 
 }*/

-(void)Back:(id)sender{
	[self.navigationController popViewControllerAnimated:YES];
}

@end
